package com.app.reportproblem.Utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.util.Base64;
import android.util.Log;

public class GetSHA {
	public static String getSHA(Activity activity) {
		PackageInfo info;
		String something = null;
		try {

			info = activity.getPackageManager().getPackageInfo(
					"com.app.reportproblem", PackageManager.GET_SIGNATURES);

			for (Signature signature : info.signatures) {
				MessageDigest md;
				md = MessageDigest.getInstance("SHA");
				md.update(signature.toByteArray());
				something = new String(Base64.encode(md.digest(), 0));
				Log.e("Hash key", something);
				System.out.println("Hash key" + something);
			}

		} catch (NameNotFoundException e1) {
			Log.e("name not found", e1.toString());
		} catch (NoSuchAlgorithmException e) {
			Log.e("no such an algorithm", e.toString());
		} catch (Exception e) {
			Log.e("exception", e.toString());
		}
		
		return something;
	}

}
